package com.example.hello.POJO;

import com.example.hello.views.organizations.Organizations;

import java.util.*;

public class OrganizationPOJO extends POJO {

    private Set<String> admins = new HashSet<>();
    private Set<String> tracks = new HashSet<>();
    private Set<String> users = new HashSet<>();

    public OrganizationPOJO() {
    }

    public OrganizationPOJO(String name) {
        this.name = name;
    }

    public Set<String> getAdmins() {
        return admins;
    }

    public void setAdmins(Set<String> admin) {
        this.admins = admin;
    }

    public void addAdmin(String admin) {
        if (!admins.contains(admin)) admins.add(admin);
    }

    public boolean removeAdmin(String admin) {
        return admins.remove(admin);
    }

    public boolean hasAdmin(String admin) {
        return admins.contains(admin);
    }

    public Set<String> getTracks() {
        return tracks;
    }

    public void setTracks(Set<String> track) {
        this.tracks = track;
    }

    public void addTrack(String track) {
        if (!tracks.contains(track)) tracks.add(track);
    }

    public boolean removeTrack(String track) {
        return tracks.remove(track);
    }

    public boolean hasTrack(String track) {
        return tracks.contains(track);
    }

    public Set<String> getUsers() {
        return users;
    }

    public void setUsers(Set<String> user) {
        this.users = user;
    }

    public void addUser(String user) {
        if (!users.contains(user)) users.add(user);
    }

    public boolean removeUser(String user) {
        return users.remove(user);
    }

    public boolean hasUser(String user) {
        return users.contains(user);
    }

    public String toString() {
        String str = "Organization:\n";

        str += "    _id: " + _id + "\n";
        str += "    name: " + name + "\n";
        str += "    tracks: " + Arrays.toString(tracks.toArray()) + "\n";
        str += "    users: " + Arrays.toString(users.toArray());

        return str;
    }

    public boolean create() {
        return create(Organizations.NAME, this);
    }

    public boolean update() {
        return update(Organizations.NAME + "/" + name, this);
    }

}